package com.lin.sppringbootdemo.service;

import com.lin.sppringbootdemo.domain.TestLin;
import com.lin.sppringbootdemo.enums.ResultEnum;
import com.lin.sppringbootdemo.exception.TestLinException;
import com.lin.sppringbootdemo.jpa.TestLinRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TestLinService {

    @Autowired
    private TestLinRepository testLinRepository;

    public void getAge(Integer id) throws Exception {
        TestLin one = testLinRepository.getOne(id);
        Integer age = one.getAge();
        if (age < 10) {
            throw new TestLinException(ResultEnum.SMALL);
        } else if (age > 10 && age < 16) {
            throw new TestLinException(ResultEnum.MIDOUN);
        }
    }

    public TestLin findOne(Integer id) {
        TestLin one = testLinRepository.getOne(id);
        return one;
    }
}